<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<title>录入运单</title>
		<link rel="stylesheet" type="text/css" href="btn_class.css" />
		<link rel="stylesheet" type="text/css"
			href="ext-2.2/resources/css/ext-all.css" />
		<link rel="stylesheet" type="text/css"
			href="ext-2.2/ext-2.2/style.css" />
		<link rel="stylesheet" type="text/css"
			href="ext-2.2/ext-2.2/desktop.css" />
		<link rel="stylesheet" type="text/css"
			href="ext-2.2/ext-2.2/ext-patch.css" />

		<script type="text/javascript" src="ext-2.2/adapter/ext/ext-base.js"></script>
		<script type="text/javascript" src="ext-2.2/ext-all.js"></script>
		<script type="text/javascript" src="js/cal.js"></script>

		<!--  	<script type="text/javascript" src="ext-2.2/source/locale/ext-lang-zh_CN.js"></script>   -->
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

		<script type="text/javascript">
		<%String uId = (String) session.getAttribute("Uid");
			if (uId == null || uId.equals("null")) {%>
			window.parent.location.href = 'index.jsp';
		<%}%>
		
		window.onload = function(){
			if("<%=request.getAttribute("enterWbFlag")%>"=="Y")
			{
				alert("录入运单成功！");
			}
			if("<%=request.getAttribute("enterWbFlag")%>"=="dup")
			{
				alert("对不起，这个运单号已经存在！");
			}
			if("<%=request.getAttribute("enterWbFlag")%>"=="N")
			{
				alert("请确定输入的客户唯一标示符是存在的！");
			}
				if("<%=request.getAttribute("enterWbFlag")%>"=="N2")
			{
				alert("请确定输入的收入标示是存在的！");
			}
			//window.parent.left.location.reload(); 
		}
		  

		
			function clearContent()
			{
				document.getElementById("wbUps").value = "";
				document.getElementById("wbEnterWeight").value = "";
				document.getElementById("Uid").value = "";
				
				document.getElementById("wbLength").value = "";
				document.getElementById("wbWidth").value = "";
				document.getElementById("wbHeight").value = "";
			}
			
			
			function enterWaybill()
			{
				var wbUps = document.getElementById("wbUps").value;
				var wbEnterWeight = document.getElementById("wbEnterWeight").value;
				var Uid = document.getElementById("Uid").value;
				var UreceiveId =  document.getElementById("UreceiveId").value;
				var flag = document.getElementById("flag");
				var managerUid =  "<%=session.getAttribute("Uid")%>";
				
				if(wbUps=="")
				{
					alert("运单号不能为空");
					return;
				}
				
				var regu =/^[A-Za-z0-9]+$/;
				var re = new RegExp(regu); 
				if (!re.test(wbUps)) { 
					alert("请输入正确的运单号,只允许字母和数字!");
					return; 
				}
				if(wbEnterWeight=="")
				{
					alert("重量不能为空");
					return;
				}
				if(!flag.checked){
					document.getElementById("UreceiveId").value = "";
					if(Uid=="")
					{
						alert("客户唯一标示符不能为空");
						return;
					}
				}else{
					document.getElementById("Uid").value = "";
					if(UreceiveId=="")
					{
						alert("收件标示符不能为空");
						return;
					}
				}
				var vFlag = false;
				var len = document.getElementById("wbLength").value;
				var wid = document.getElementById("wbWidth").value;
				var hei = document.getElementById("wbHeight").value;
				if(len==""&&wid==""&&hei==""){
					vFlag = true
				}
				if(len!=""&&wid!=""&&hei!=""){
					vFlag = true
				}  
				if(!vFlag){
					alert("请同时输入长宽高或者都不输入！");
					return;
				}
				
				if(len!=""&&wid!=""&&hei!=""){
					var vEnterWeight = fomatFloat(document.getElementById("wbEnterWeight").value,2);
					var vWeight = fomatFloat(FloatDiv(fomatFloat(FloatMul(fomatFloat(FloatMul(len,wid),2),hei),2),166),2);
					if(FloatSub(vWeight,vEnterWeight*1)>0){
						alert("对不起，体积重量是"+vWeight+",大于物理重量"+vEnterWeight+",请修改重量!");
						return;
					}
				}

		   		 Ext.Ajax.request({ 
		             //请求地址 
		             url: 'waybill!checkWaybillExist.do', 
		             //提交参数组 
		             params: { 
		                 wbUps : Ext.get('wbUps').dom.value.trim()
		             }, 
		             //成功时回调 
		             success: function(response, options) { 
		                //获取响应的json字符串 
		               var responseArray = Ext.util.JSON.decode(response.responseText);                                               
		                    if(responseArray.success==true){ 
		                    	var f = document.forms["enterWaybillForm"];
		        				//parent.window.location = "waybill!enterWaybill.do";
		        				f.action = "waybill!enterWaybill.do?managerUid="+managerUid;
		        				f.submit();
		                    } 
		                    else{ 
		                    	alert("对不起,该快递号已经存在!");
		    			   		return;
		                    } 
		            } 
		   		 }); 

				
			}
			
			function enterToWaybill()
			{
				if (event.keyCode == 13)
				{
					 enterWaybill();
				}
			}
			
			function showUreceive(){
				var flag = document.getElementById("flag");
				var flag1 = document.getElementById("flag1");
				var flag2 = document.getElementById("flag2");
				if(flag.checked){
					flag1.style.display = 'none';
					flag2.style.display = '';
				}else{
					flag1.style.display = '';
					flag2.style.display = 'none';
				}
			}
			
	</script>
	</head>

	
<body style="background:white"> 
	<div class="x-panel-header x-panel-header-noborder x-unselectable" id="ext-gen8" style="mozuserselect: none; khtmluserselect: none;" unselectable="on">
		<span class="x-panel-header-text" >录入运单</span>
	</div>
		<form name="enterWaybillForm" method="post">
		 <table width="300px" border="0" cellSpacing="3" cellPadding="3">
		 	<tr>
		 		<td align="right"><font style="font-size:15px">运单号：</font></td>
		 		<td align="left"><input name="wbUps" id="wbUps" size="15" maxLength="22"/><font color="#ff0000">*</font></td>
		 	</tr>
		 	<tr>
		 		<td align="right"><font style="font-size:15px">重量：</font></td>
		 		<td align="left"><input name="wbEnterWeight" id="wbEnterWeight" size="15" maxLength="22"/><font color="#ff0000">LBS *</font></td>
		 	</tr>
		 	<tr>
		 		<td align="right"><font style="font-size:15px">仓库：</font></td>
		 		<td align="left">
		 		<select name="wbArea" style="width:125px">
  						<option value ="CA">CA</option>
  						<option value ="OR">OR</option>
  						<option value ="NK">New York</option>
				</select>
				<font color="#ff0000">*</font>
				</td>
		 	</tr>
		 	<tr id="flag1" style="display:''">
		 		<td align="right"><font style="font-size:15px">客户唯一标示符：</font></td>
		 		<td align="left"><input name="Uid" id="Uid" size="15" maxLength="22"  onkeypress="enterToWaybill();"/><font color="#ff0000">*</font></td>
		 	</tr>
		 	<tr style="display:none" id="flag2">
		 		<td align="right"><font style="font-size:15px">收件标示：</font></td>
		 		<td align="left"><input name="UreceiveId" id="UreceiveId" size="15" maxLength="22"  onkeypress="enterToWaybill();"/><font color="#ff0000">*</font></td>
		 	</tr>
		 	<tr>
		 		<td align="right"><font style="font-size:15px">长度：</font></td>
		 		<td align="left"><input id="wbLength" size="15" maxLength="22"/></td>
		 	</tr>
		 	<tr>
		 		<td align="right"><font style="font-size:15px">宽度：</font></td>
		 		<td align="left"><input id="wbWidth" size="15" maxLength="22"/></td>
		 	</tr>
		 	<tr>
		 		<td align="right"><font style="font-size:15px">高度：</font></td>
		 		<td align="left"><input id="wbHeight" size="15" maxLength="22"/></td>
		 	</tr>
		 	<tr>
		 		<td align="right"><font style="font-size:15px">显示收件标示：</font></td>
		 		<td align="left"><input type="checkbox" id="flag" onclick="showUreceive()" /></td>
		 	</tr>
		 	<tr>
		 		<td align="center">
		 			<input  type="button" class="submit_btn"  onclick="enterWaybill();" value="录入" />
		 		</td>
		 		<td align="center">
		 			<input  type="button" class="submit_btn"  onclick="clearContent();" value="重置" />
		 		</td>
		 	</tr>
		 	
		 </table>
		  
           </form>
		
    </body> 
</html>
